package com.oyc.demo.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class LogCostInterceptor implements HandlerInterceptor {
	
	/*方法一：prehandle()是在处理请求之前进行调用，执行controller的任务之前调用，
	 * 返回true继续执行，返回false放弃执行*/
	
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
    	HttpSession session=httpServletRequest.getSession();
    	String url=httpServletRequest.getRequestURL().toString();
    	
    	/*if(has(url)){
    		if(session.getAttribute("provincename")==null||session.getAttribute("provincename").toString().trim().length()==0){
    			httpServletResponse.sendRedirect("/chx/login");
        		return false;
        	}
    	}*/
    	
        return true;
    }
 
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        
    }
 
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
    }
    
    private boolean has(String url){
    	for (int i = 0; i < urls.length; i++) {
			if(url.contains(urls[i])){
				return true;
			}
		}
    	return false;
    }
    
    private String[] urls={"chx/client/update","chx/client/exportexcel","chx/client/selectbycondition"};
}
